package org.example.hengshengexam;

import java.util.ArrayList;
import java.util.List;

// 学生类
class Student {
    private String id;
    private String name;
    private int age;

    public Student(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    // getter 和 setter 方法（略）
    public String getId() { return id; }
    public String getName() { return name; }
    public int getAge() { return age; }
    public void setName(String name) { this.name = name; }
    public void setAge(int age) { this.age = age; }

    @Override
    public String toString() {
        return "学生ID：" + id + "，姓名：" + name + "，年龄：" + age;
    }
}

// 学生管理系统类
public class StudentManagementSystem {
    private List<Student> students = new ArrayList<>();

    // 添加学生
    public void addStudent(Student student) {
        students.add(student);
        System.out.println("添加学生成功：" + student);
    }

    // 删除学生
    public void removeStudent(String id) {
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).getId().equals(id)) {
                students.remove(i);
                System.out.println("删除学生ID为" + id + "的学生成功");
                return;
            }
        }
        System.out.println("未找到ID为" + id + "的学生");
    }

    // 修改学生信息
    public void modifyStudent(String id, String newName, int newAge) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                student.setName(newName);
                student.setAge(newAge);
                System.out.println("修改学生信息成功，当前信息：" + student);
                return;
            }
        }
        System.out.println("未找到ID为" + id + "的学生");
    }

    // 查询学生信息
    public void queryStudent(String id) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                System.out.println("查询到学生：" + student);
                return;
            }
        }
        System.out.println("未找到ID为" + id + "的学生");
    }

    // 主方法测试
    public static void main(String[] args) {
        StudentManagementSystem sms = new StudentManagementSystem();
        sms.addStudent(new Student("S001", "张三", 20));
        sms.queryStudent("S001");
        sms.modifyStudent("S001", "李四", 21);
        sms.removeStudent("S001");
        sms.queryStudent("S001");
    }
}